package util

import "encoding/json"

type BaseInfo struct {
	OrderType    string `json:"orderType"`
	PurchaserID  string `json:"purchaserId"`
	ServiceType  string `json:"serviceType"`
	SalesChannel string `json:"salesChannel"`
	TerminalType string `json:"terminalType"`
}

type OrdinaryProduct struct {
	ProductID        string  `json:"productId"`
	ProductVersionID string  `json:"productVersionId"`
	StandardPrice    float64 `json:"standardPrice"`
	MinimumPrice     float64 `json:"minimumPrice"`
	SellingCount     int     `json:"sellingCount"`
	SellingAmount    string `json:"sellingAmount"`
}

type ProductInfo struct {
	OrdinaryProductList []OrdinaryProduct `json:"ordinaryProductList"`
	ReductionReason string `json:"reductionReason"`
}

type InvoiceInfo struct {
	InvoiceType      string `json:"invoiceType"`
	InvoiceTitleType string `json:"invoiceTitleType"`
	Title            string `json:"title"`
}

type DeliveryInfo struct {
	ReceiverEmail  string `json:"receiverEmail"`
	ReceiverMobile string `json:"receiverMobile"`
	LocationCode   string `json:"locationCode"`
}

type ContactInfo struct {
	ContactName string `json:"contactName"`
	Phone       string `json:"phone"`
	Gender      string `json:"gender"`
	Role        string `json:"role"`
}

type OrderRemark struct {
	SignerID     string `json:"signerId"`
	OperatorType string `json:"operatorType"`
	OperatorID   string `json:"operatorId"`
}

type AccountDeduct struct {
	AccountID       int    `json:"accountId"`
	AccountType     string `json:"accountType"`
	TradeAmount     int    `json:"tradeAmount"`
	AvailableAmount int    `json:"availableAmount"`
}

type BalanceDeductInfo struct {
	CustomerIdentityID  int           `json:"customerIdentityId"`
	CouponDeductAmount  int           `json:"couponDeductAmount"`
	AccountDeductAmount int           `json:"accountDeductAmount"`
	InvoiceAmount       int           `json:"invoiceAmount"`
	CouponDeductList    []interface{} `json:"couponDeductList"`
	AccountDeductList   []AccountDeduct `json:"accountDeductList"`
}


type PayInfo struct {
	PaymentWay        string `json:"paymentWay"`
	BalanceDeductInfo  `json:"balanceDeductInfo"`
}

type Order struct {
	BaseInfo  `json:"baseInfo"`
	ProductInfo  `json:"productInfo"`
	InvoiceBeforePaid string `json:"invoiceBeforePaid"`
	InvoiceInfo `json:"invoiceInfo"`
	DeliveryInfo  `json:"deliveryInfo"`
	ContactInfo  `json:"contactInfo"`
	OrderRemark  `json:"orderRemark"`
	//PayInfo `json:"payInfo"`
}

func SetOrder(purchaserId string, customerIdentityId int, accountId int, isPay bool) string {

	baseInfo := BaseInfo{
		OrderType:    "0",
		PurchaserID:  purchaserId,
		ServiceType:  "01",
		SalesChannel: "50",
		TerminalType: "1",
	}

	var ordinaryProductList []OrdinaryProduct

	ordinaryProductA := OrdinaryProduct{
		ProductID:        "32575",
		ProductVersionID: "56121",
		StandardPrice:    0.1,
		MinimumPrice:     0.1,
		SellingCount:     1,
		SellingAmount:    "0.1",
	}

	ordinaryProductB := OrdinaryProduct{
		ProductID:        "32574",
		ProductVersionID: "56173",
		StandardPrice:    11,
		MinimumPrice:     11,
		SellingCount:     1,
		SellingAmount:    "11",
	}

	ordinaryProductC := OrdinaryProduct{
		ProductID:        "32573",
		ProductVersionID: "56148",
		StandardPrice:    6000,
		MinimumPrice:     6000,
		SellingCount:     1,
		SellingAmount:    "88.9",
	}

	reductionReason := "性能测试备注"
	ordinaryProductList = append(ordinaryProductList, ordinaryProductA, ordinaryProductB, ordinaryProductC)

	productInfo := ProductInfo{
		OrdinaryProductList: ordinaryProductList,
		ReductionReason:     reductionReason,
	}

	//invoiceBeforePaid := "0"
	invoiceBeforePaid := "1"

	invoiceInfo := InvoiceInfo{
		InvoiceType:      "4",
		InvoiceTitleType: "2",
		Title:            "性能测试开票",
	}

	deliveryInfo := DeliveryInfo{
		ReceiverEmail:  "11@qq.com",
		ReceiverMobile: "13635534591",
		LocationCode:   "",
	}

	contactInfo := ContactInfo{
		ContactName: "河北-测试-1",
		Phone:       "",
		Gender:      "0",
		Role:        "",
	}

	orderRemark := OrderRemark{
		SignerID:     "b763cad2fe2542018602d41fccc4ee39",
		OperatorType: "2",
		OperatorID:   "b763cad2fe2542018602d41fccc4ee39",
	}

	var accountDeductList  []AccountDeduct
	accountDeductA := AccountDeduct{
		AccountID:       accountId,
		AccountType:     "CASH",
		TradeAmount:     100,
		AvailableAmount: 9900,
	}
	accountDeductList = append(accountDeductList, accountDeductA)

	//balanceDeductInfo := BalanceDeductInfo{
	//	CustomerIdentityID: customerIdentityId,
	//	CouponDeductAmount:  0,
	//	AccountDeductAmount: 100,
	//	InvoiceAmount:       0,
	//	CouponDeductList:    nil,
	//	AccountDeductList:   accountDeductList,
	//}

	//payInfo := PayInfo{}
	//if isPay {
	//	payInfo = PayInfo{
	//		PaymentWay:        "2",
	//		BalanceDeductInfo: balanceDeductInfo,
	//	}
	//}

	order := Order{
		BaseInfo:          baseInfo,
		ProductInfo:       productInfo,
		InvoiceBeforePaid: invoiceBeforePaid,
		InvoiceInfo:       invoiceInfo,
		DeliveryInfo:      deliveryInfo,
		ContactInfo:       contactInfo,
		OrderRemark:       orderRemark,
		//PayInfo:           payInfo,
	}

	orderJson, err := json.Marshal(order)
	CheckErr(err)

	return string(orderJson)
}